package com.vnp.cooking;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.TextView;

public class RegisterActivity extends Activity implements OnClickListener{

	ImageButton btnBack;
	TextView title_register;
	
	WebView webRegister;
	ProgressBar progressBar;
	
	String urlRegister = "http://anuong.net/api/register";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_register);
		
		btnBack = (ImageButton) findViewById(R.id.btn_back);
		title_register = (TextView) findViewById(R.id.title_register);
		webRegister = (WebView) findViewById(R.id.web_register);
		
		progressBar = (ProgressBar) findViewById(R.id.progressBarRes);
		progressBar.setVisibility(ProgressBar.GONE);
		
		webRegister.getSettings().setJavaScriptEnabled(true);
		webRegister.setWebChromeClient(new WebChromeClient() {
		            public void onProgressChanged(WebView view, int progress) {
		                progressBar.setProgress(progress);
		                if (progress == 100) {
		                	progressBar.setVisibility(ProgressBar.INVISIBLE);
		                    progressBar.setProgress(0);
		                } else {
		                	progressBar.setVisibility(ProgressBar.VISIBLE);
		                }
		            }
		        });
		webRegister.setWebViewClient(new MyWebViewClient());
		webRegister.loadUrl(urlRegister);
		
		
		init();
	}
	
	
	private void init() {
		btnBack.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_back:
			closeActivity();
			break;

		default:
			break;
		}
	}
	
	private class MyWebViewClient extends WebViewClient {
	    @Override
	    public boolean shouldOverrideUrlLoading(WebView view, String url) {
	       view.loadUrl(url);
	        return true;
	    }
	    
	}
	
	
	void closeActivity(){
		finish();
		overridePendingTransition(R.anim.open_main, R.anim.close_next);
	}


	@Override
	public void onBackPressed() {
		closeActivity();
	}
	
}
